package com.chuyu.jzwboa.activity.log;

import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.chuyu.jzwboa.R;
import com.chuyu.jzwboa.base.MVPBaseActivity;
import com.chuyu.jzwboa.presenter.log.WriteLogPresenter;
import com.chuyu.jzwboa.utils.sys.ScreenUtils;
import com.chuyu.jzwboa.utils.sys.StatusBarUtils;
import com.chuyu.jzwboa.view.log.IWriteLogView;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 日志---》(编写日志)
 */
public class WriteLogActivity extends MVPBaseActivity<IWriteLogView, WriteLogPresenter> implements IWriteLogView, View.OnClickListener {


	@BindView(R.id.tv_cancel_writelog)
	TextView tvCancelWritelog;
	@BindView(R.id.tv_sumbit_writelog)
	TextView tvSumbitWritelog;
	@BindView(R.id.rl_log)
	RelativeLayout rlLog;
	@BindView(R.id.tv_log_date)
	TextView tvLogDate;
	@BindView(R.id.iv_down)
	ImageView ivDown;
	@BindView(R.id.rl_log_date)
	RelativeLayout rlLogDate;
	@BindView(R.id.view_writelog)
	View viewWritelog;
	@BindView(R.id.ed_writelog)
	EditText edWritelog;
	@BindView(R.id.remarkLenth1)
	TextView remarkLenth1;
	private WriteLogPresenter writeLogPresenter;

	@NonNull
	@Override
	public WriteLogPresenter createPresenter() {
		writeLogPresenter = new WriteLogPresenter();
		return writeLogPresenter;
	}

	@Override
	protected int initContent() {
		return R.layout.activity_write_log;
	}

	@Override
	protected void initView() {
		tvCancelWritelog.setOnClickListener(this);
		rlLog.setOnClickListener(this);
	}

	@Override
	protected void initData() {
		/**
		 * 动态设置状态栏高度
		 */
		int statusHeight = StatusBarUtils.getStatusHeight(this);
		rlLog.setPadding(0, statusHeight, 0, 0);
	}

	@Override
	public void showPorgressBar() {

	}

	@Override
	public void closePorfressBar() {

	}

	@Override
	public void LoginSuccess() {

	}

	@Override
	public void LoginFailed() {

	}

	@Override
	public void LoadExpetion() {

	}


	@Override
	public void onClick(View view) {
		switch (view.getId()) {
			case R.id.tv_cancel_writelog:
				showPopupWindow();
				break;
			case R.id.rl_log:
				break;
		}
	}

	private void showPopupWindow() {
		final View mMenuView = getLayoutInflater().from(getApplicationContext()).inflate(R.layout.popupwindow_log, null);
		final PopupWindow popupWindow = new PopupWindow(mMenuView, ScreenUtils.getScreenWidth(getApplicationContext()), ScreenUtils.getScreenHeight(getApplicationContext()));
		popupWindow.setClippingEnabled(false);
		TextView tv_savedraft = (TextView) mMenuView.findViewById(R.id.tv_savedraft);
		TextView tv_nosave = (TextView) mMenuView.findViewById(R.id.tv_nosave);
		TextView tv_popupdimeds = (TextView) mMenuView.findViewById(R.id.tv_popupdimeds);
		// 取消按钮
		tv_popupdimeds.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				// 销毁弹出框
				popupWindow.dismiss();
				finish();
			}
		});
		//设置弹出窗体可点击
		popupWindow.setFocusable(true);
		// 设置外部可点击
		popupWindow.setOutsideTouchable(true);
		popupWindow.setBackgroundDrawable(new BitmapDrawable());
		// mMenuView添加OnTouchListener监听判断获取触屏位置如果在选择框外面则销毁弹出框
		mMenuView.setOnTouchListener(new View.OnTouchListener() {
			public boolean onTouch(View v, MotionEvent event) {
				int height = mMenuView.findViewById(R.id.pop_layout).getTop();
				int y = (int) event.getY();
				if (event.getAction() == MotionEvent.ACTION_UP) {
					if (y < height) {
						popupWindow.dismiss();
					}
				}
				return true;
			}
		});
		// /* 设置弹出窗口特征 */
		// 设置视图
		popupWindow.setContentView(mMenuView);
		// 设置弹出窗体显示时的动画，从底部向上弹出
		popupWindow.setAnimationStyle(R.style.take_photo_anim);
		popupWindow.showAtLocation(findViewById(R.id.main_view),
				Gravity.BOTTOM, 0, 0);
	}


}
